package com.yc.controller;


import org.springframework.web.bind.annotation.*;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import java.security.Principal;
import java.util.Map;

/**
 * @author yangc91
 * @date 2020/8/22 15:06
 */
@RestController
@RequestMapping("/test")
public class PermissionPoliyController {
    @GetMapping("/admin")
    public Object getToken(HttpServletRequest request) {
//        Keycloak kc = Keycloak.getInstance("http://localhost:8080/auth",
//                 credentials.get("company"),
//                 credentials.get("username"),
//                credentials.get("password"),
//                credentials.get("clientId"));
//
//        return kc.tokenManager().getAccessToken();
        Principal userPrincipal = request.getUserPrincipal();
        return "admin";

    }
    @GetMapping("/loginOut")
    public Object loginOut(HttpServletRequest request) {
//        Keycloak kc = Keycloak.getInstance("http://localhost:8080/auth",
//                 credentials.get("company"),
//                 credentials.get("username"),
//                credentials.get("password"),
//                credentials.get("clientId"));
//
//        return kc.tokenManager().getAccessToken();
        try {
            request.logout();
        } catch (ServletException e) {
            e.printStackTrace();
            return "failed";
        }
        return "success";

    }
    @GetMapping(path = "/customer/view")
    public String index() {
        return "customer/view";
    }

    @GetMapping(path = "/customer/delete")
    public String customers(HttpServletRequest request) {


        return "/customer/delete";
    }

}
